package com.gwt.client.ui.widget.editor;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.ui.client.ValueBoxEditorDecorator;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Widget;
import com.gwt.shared.BeerProxy;

public class BeerEditor extends Composite implements Editor<BeerProxy> {

	interface Binder extends UiBinder<Widget, BeerEditor> {
	}

	@UiField(provided = true)
	BeerStyleEditor styleEditor;

	@UiField
	ValueBoxEditorDecorator<String> description;

	@UiField
	ValueBoxEditorDecorator<String> name;

	@UiField
	ValueBoxEditorDecorator<String> note;

	@UiField
	Focusable nameBox;

	public BeerEditor(BeerStyleEditor styleEditor) {
		this.styleEditor = styleEditor;
		initWidget(GWT.<Binder> create(Binder.class).createAndBindUi(this));
	}

	public void focus() {
		Scheduler.get().scheduleDeferred(new ScheduledCommand() {

			@Override
			public void execute() {
				nameBox.setFocus(true);
			}
		});
	}

}
